import axios from 'axios';

import {
  Toast
} from 'antd-mobile';

const isDev = process.env.NODE_ENV === 'development';
const ajax = axios.create({
  baseURL: isDev ? 'http://rap2api.taobao.org/app/mock/117548' : '真实的api地址'
})

ajax.interceptors.request.use(config => {
  Toast.loading('加载中…',0);
  return config;
})

ajax.interceptors.response.use(resp => {
  Toast.hide();
  return resp.data;
  // 根据实际项目接口先console出来看看。格式要统一。
  // if(resp.code === 200 && resp.msg === 'OK') {
  //   return resp.data.data
  // } else{
  //   Toast.fail(resp.msg)
  //   return resp.data
  // }
})

export const getSwiper = ()=> {
  return ajax.get('/api/version-1/caroussel');
}

export const getCategory = ()=> {
  return ajax.get('/api/category');
}

export const getCategoryListById = (id)=> {
  return ajax.get(`/api/categorylist/${id}`);
}

export const getProductDetail = (id)=> {
  return ajax.get(`/api/detail/${id}`);
}

export const login = (userinfo)=> {
  return ajax.post('/api/login', userinfo);
}

export const checkAuthApi = (token)=> {
  return axios.post('http://rap2api.taobao.org/app/mock/117548/api/user/checkAuth', {token});
}